//
//  NSString+ACPValueType.m
//  AutoCreatePropertyDemo
//
//  Created by Hongwei Wang on 2017/11/25.
//  Copyright © 2017年 puhui. All rights reserved.
//

#import "NSString+ACPValueType.h"

@implementation NSString (ACPValueType)

- (id)toJsonObj {
    if (self == nil) {
        return nil;
        
    }
    NSData *jsonData = [self dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    id dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                             options:NSJSONReadingMutableContainers
                                               error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}

- (BOOL)isPureInt {
    NSScanner* scan = [NSScanner scannerWithString:self];
    NSInteger val;
    return [scan scanInteger:&val] && [scan isAtEnd];
}

- (BOOL)isPureFloat {
    NSScanner* scan = [NSScanner scannerWithString:self];
    double val;
    return [scan scanDouble:&val] && [scan isAtEnd];
}

- (NSString *)uppercaseFirstChar {
    NSString *firstChar = [self substringToIndex:1];
    firstChar = [firstChar uppercaseString];
    NSString *other = [self substringFromIndex:1];
    return [firstChar stringByAppendingString:other];
}

@end
